package crane.bomb;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.util.HashMap;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * 
 * @author crane
 *
 */
public class BombScoreInputWindow  extends JDialog{

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 7406733816447367116L;
    
//    public static void main(String args[]){
//        JFrame frame = new JFrame();
//        frame.setBounds(200, 200, 300, 200);
//        frame.setVisible(true);
//        Map map = new HashMap();
//        map.put("LEVEL", "5");
//        map.put("TIME", "125");
//        new BombScoreInputWindow(frame, map);
//    }

    /**
     * Constructor
     * 
     * @param frame
     * @param paramMap
     *    KEYS: LEVEL, SCORE
     */
    public BombScoreInputWindow(JFrame frame, Map paramMap){
        super(frame, true);
        try{
            this.setResizable(false);
            this.setTitle("Please input your Name!");
            Container cp = this.getContentPane();
            cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS));
            this.addWindowListener(new ActionAdapter(){
                public void windowClosing(WindowEvent we) {
                    BombScoreInputWindow.this.dispose();
                }
            });
            cp.setBounds(400, 250, 260, 200);
            
            JPanel panel = new JPanel();
            panel.setLayout(new GridLayout(3, 2));
            panel.setBorder(BorderFactory.createTitledBorder("Your Score Information:"));
            
            JLabel label = new JLabel();
            label.setText("Your Level:");
            JTextField text = new JTextField();
            text.setText(paramMap.get("LEVEL").toString());
            text.setEnabled(false);
            text.setPreferredSize(new Dimension(40, 30));
            panel.add(label);
            panel.add(text);
            
            label = new JLabel();
            label.setText("Your Time:");
            text = new JTextField();
            text.setText(paramMap.get("TIME").toString());
            text.setEnabled(false);
            text.setPreferredSize(new Dimension(40, 30));
            panel.add(label);
            panel.add(text);
            
            label = new JLabel("Player Name:  ");            
            nameText = new JTextField();
            nameText.setFocusable(true);
            nameText.setPreferredSize(new Dimension(60, 30));
            panel.add(label);
            panel.add(nameText);
            panel.setVisible(true);
            cp.add(panel);
            cp.add(Box.createVerticalStrut(30));

            panel = new JPanel();
            JButton btn_OK = new JButton("OK");
            btn_OK.setFocusable(true);
            btn_OK.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae) {
                    BombScoreInputWindow.this.dispose();
                }
            });
            panel.add(btn_OK);

            cp.add(panel);
            cp.setVisible(true); 
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    
    private JTextField nameText = null;
    
    /**
     * @return String
     */
    public String getPlayerName(){
        return this.nameText.getText();
    }
}
